﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Back.Xinkui.Entity.Company;
using CommonFramework.Utility;
using Back.Xinkui.Common;
using Back.Xinkui.DataAccess.Company;

public partial class company_list : System.Web.UI.Page
{
    protected List<CompanyListEntity> CompanyList
    { get; set; }

    protected bool IsBuyer
    {
        get
        {
            return WebHelper.GetQueryStringValue<int>("isBuy", 0) > 0;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = ddlPageCount.SelectedValue.ToType<int>(10);
            BindCompanyList();
        }
    }

    protected void BindCompanyList()
    {
        string where = IsBuyer ? " AND MemberType >= 100" : " AND MemberType < 100";

        if (!string.IsNullOrEmpty(this.txtCompanyName.Text))
        {
            where += " AND CompanyName Like '%" + this.txtCompanyName.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.txtEmail.Text))
        {
            where += " AND CompanyEmail Like '%" + this.txtEmail.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.ddpStatus.SelectedValue))
        {
            where += " AND AuditStatus = " + this.ddpStatus.SelectedValue;
        }

        Pager page = new Pager { PageIndex = AspNetPager1.CurrentPageIndex, PageSize = AspNetPager1.PageSize };

        CompanyList = CompanyDataAccess.GetCompanyList(where, page);

        AspNetPager1.RecordCount = page.TotalCount;
    }

    protected void btnSerach_Click(object sender, EventArgs e)
    {
        BindCompanyList();
    }

    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindCompanyList();
    }
    /// <summary>
    /// 切换每页显示数据行数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlPageCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        AspNetPager1.PageSize = Convert.ToInt32(ddlPageCount.SelectedValue);
        BindCompanyList();
    }
}